from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-02-18 14:16:27.640031
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 18, Feb, 2021
Time: 14:16:32
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.2729
Nobs: 206.000 HQIC: -47.1388
Log likelihood: 2375.15 FPE: 1.87407e-21
AIC: -47.7269 Det(Omega_mle): 1.22323e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.464490 0.138982 3.342 0.001
L1.Burgenland 0.078195 0.071176 1.099 0.272
L1.Kärnten -0.217973 0.060231 -3.619 0.000
L1.Niederösterreich 0.132792 0.165752 0.801 0.423
L1.Oberösterreich 0.246266 0.145292 1.695 0.090
L1.Salzburg 0.208665 0.076675 2.721 0.007
L1.Steiermark 0.097929 0.103560 0.946 0.344
L1.Tirol 0.141143 0.069207 2.039 0.041
L1.Vorarlberg -0.011125 0.063199 -0.176 0.860
L1.Wien -0.125633 0.136337 -0.921 0.357
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.477813 0.168058 2.843 0.004
L1.Burgenland 0.014229 0.086067 0.165 0.869
L1.Kärnten 0.354842 0.072831 4.872 0.000
L1.Niederösterreich 0.119126 0.200429 0.594 0.552
L1.Oberösterreich -0.132549 0.175688 -0.754 0.451
L1.Salzburg 0.194063 0.092716 2.093 0.036
L1.Steiermark 0.206715 0.125225 1.651 0.099
L1.Tirol 0.142248 0.083685 1.700 0.089
L1.Vorarlberg 0.160156 0.076421 2.096 0.036
L1.Wien -0.523420 0.164860 -3.175 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.314712 0.061715 5.099 0.000
L1.Burgenland 0.103429 0.031606 3.272 0.001
L1.Kärnten -0.017999 0.026746 -0.673 0.501
L1.Niederösterreich 0.079046 0.073603 1.074 0.283
L1.Oberösterreich 0.288332 0.064517 4.469 0.000
L1.Salzburg -0.001031 0.034048 -0.030 0.976
L1.Steiermark -0.015127 0.045986 -0.329 0.742
L1.Tirol 0.086540 0.030731 2.816 0.005
L1.Vorarlberg 0.108802 0.028064 3.877 0.000
L1.Wien 0.059117 0.060541 0.976 0.329
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.224275 0.069982 3.205 0.001
L1.Burgenland -0.005913 0.035840 -0.165 0.869
L1.Kärnten 0.021447 0.030328 0.707 0.479
L1.Niederösterreich 0.039948 0.083462 0.479 0.632
L1.Oberösterreich 0.382682 0.073160 5.231 0.000
L1.Salzburg 0.087851 0.038608 2.275 0.023
L1.Steiermark 0.180746 0.052146 3.466 0.001
L1.Tirol 0.039625 0.034848 1.137 0.256
L1.Vorarlberg 0.088297 0.031823 2.775 0.006
L1.Wien -0.060139 0.068651 -0.876 0.381
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.518157 0.139324 3.719 0.000
L1.Burgenland 0.061721 0.071351 0.865 0.387
L1.Kärnten 0.017449 0.060379 0.289 0.773
L1.Niederösterreich -0.024263 0.166160 -0.146 0.884
L1.Oberösterreich 0.134836 0.145649 0.926 0.355
L1.Salzburg 0.058118 0.076863 0.756 0.450
L1.Steiermark 0.126898 0.103815 1.222 0.222
L1.Tirol 0.211563 0.069377 3.049 0.002
L1.Vorarlberg 0.027077 0.063355 0.427 0.669
L1.Wien -0.122176 0.136672 -0.894 0.371
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166695 0.098299 1.696 0.090
L1.Burgenland -0.013409 0.050342 -0.266 0.790
L1.Kärnten -0.008888 0.042600 -0.209 0.835
L1.Niederösterreich 0.113412 0.117233 0.967 0.333
L1.Oberösterreich 0.379380 0.102762 3.692 0.000
L1.Salzburg -0.019559 0.054230 -0.361 0.718
L1.Steiermark -0.021620 0.073246 -0.295 0.768
L1.Tirol 0.185321 0.048949 3.786 0.000
L1.Vorarlberg 0.045636 0.044699 1.021 0.307
L1.Wien 0.180271 0.096429 1.869 0.062
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.235378 0.126585 1.859 0.063
L1.Burgenland 0.053834 0.064828 0.830 0.406
L1.Kärnten -0.036613 0.054858 -0.667 0.505
L1.Niederösterreich -0.024643 0.150967 -0.163 0.870
L1.Oberösterreich -0.083608 0.132332 -0.632 0.528
L1.Salzburg 0.045703 0.069835 0.654 0.513
L1.Steiermark 0.395391 0.094323 4.192 0.000
L1.Tirol 0.482700 0.063034 7.658 0.000
L1.Vorarlberg 0.164701 0.057562 2.861 0.004
L1.Wien -0.231375 0.124176 -1.863 0.062
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.081636 0.152963 0.534 0.594
L1.Burgenland 0.032918 0.078337 0.420 0.674
L1.Kärnten -0.077033 0.066290 -1.162 0.245
L1.Niederösterreich 0.267611 0.182426 1.467 0.142
L1.Oberösterreich -0.029348 0.159908 -0.184 0.854
L1.Salzburg 0.243626 0.084388 2.887 0.004
L1.Steiermark 0.137804 0.113978 1.209 0.227
L1.Tirol 0.059163 0.076169 0.777 0.437
L1.Vorarlberg 0.056960 0.069557 0.819 0.413
L1.Wien 0.230979 0.150052 1.539 0.124
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.586177 0.082333 7.120 0.000
L1.Burgenland -0.037745 0.042165 -0.895 0.371
L1.Kärnten -0.013292 0.035681 -0.373 0.710
L1.Niederösterreich -0.032012 0.098191 -0.326 0.744
L1.Oberösterreich 0.307508 0.086071 3.573 0.000
L1.Salzburg 0.017437 0.045422 0.384 0.701
L1.Steiermark 0.005646 0.061349 0.092 0.927
L1.Tirol 0.079211 0.040998 1.932 0.053
L1.Vorarlberg 0.122035 0.037439 3.260 0.001
L1.Wien -0.028408 0.080766 -0.352 0.725
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.137002 0.031911 0.198525 0.251664 0.061728 0.101221 -0.049875 0.168491
Kärnten 0.137002 1.000000 0.010792 0.194443 0.165637 -0.118892 0.147423 0.004838 0.321895
Niederösterreich 0.031911 0.010792 1.000000 0.298189 0.082405 0.211363 0.133574 0.049095 0.363593
Oberösterreich 0.198525 0.194443 0.298189 1.000000 0.298393 0.292485 0.096878 0.076049 0.132806
Salzburg 0.251664 0.165637 0.082405 0.298393 1.000000 0.151438 0.055252 0.091253 -0.012154
Steiermark 0.061728 -0.118892 0.211363 0.292485 0.151438 1.000000 0.101977 0.105014 -0.106241
Tirol 0.101221 0.147423 0.133574 0.096878 0.055252 0.101977 1.000000 0.160795 0.159898
Vorarlberg -0.049875 0.004838 0.049095 0.076049 0.091253 0.105014 0.160795 1.000000 0.034992
Wien 0.168491 0.321895 0.363593 0.132806 -0.012154 -0.106241 0.159898 0.034992 1.000000